<?php

namespace App\Http\Middleware;

use App\Http\Controllers\IndexController;
use Closure;
use Illuminate\Support\Facades\Cookie;

class CheckLogin
{
    public $index;
    public function __construct(IndexController $index)
    {
        $this->index = $index;
    }
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $login = Cookie::get('open_id');
        if (empty($login)) {
            $this->index->oauth($request);
        }
        return $next($request);
    }
}
